package com.wdy.po;

import java.io.Serializable;
import java.util.Date;

import com.wdy.util.BasicUtil;
@SuppressWarnings({"unchecked", "serial"})
public class Post implements Comparable, Serializable {

	private Integer poid;
	private Date date;
	private String title;
	private String content;
	private User user;
	
	public Post() {
		super();
	}

	public Post(Integer poid, Date date, String title, String content, User user) {
		super();
		this.poid = poid;
		this.date = date;
		this.title = title;
		this.content = content;
		this.user = user;
	}

	public Integer getPoid() {
		return poid;
	}

	public void setPoid(Integer poid) {
		this.poid = poid;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
/*
	@Override
	public boolean equals(Object o) {
		if(null == o) {
			return false;
		}
		if(o instanceof Post){
			Post contrastPost = (Post)o;
			Integer contrastPoid = contrastPost.getPoid();
			Date contrastDate = contrastPost.getDate();
			if(this.poid.equals(contrastPoid) && this.date.equals(contrastDate)){
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		return this.poid.hashCode() * this.date.hashCode();
	}
*/
	@Override
	public String toString() {
		return this.date.toString() + this.title;
	}

	public int compareTo(Object o) {
		Post contrastPost = (Post)o;
		Integer contrastPoid = contrastPost.getPoid();
		int orignalId = this.poid.intValue();
		int contrastId = contrastPoid.intValue();
		return BasicUtil.compare(orignalId, contrastId);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((date == null) ? 0 : date.hashCode());
		result = prime * result + ((poid == null) ? 0 : poid.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof Post))
			return false;
		final Post other = (Post) obj;
		if (date == null) {
			if (other.date != null)
				return false;
		} else if (!date.equals(other.date))
			return false;
		if (poid == null) {
			if (other.poid != null)
				return false;
		} else if (!poid.equals(other.poid))
			return false;
		return true;
	}
}
